define(function(require, exports, module) {
	"use strict";
	require("../../dep/mui/js/mui.min.js");
	require("../jquery-3.1.1.min.js");
	var abpUse = require("../abp.js");
	var abp = abpUse.abpstart;
	//钉钉返回
	require('http://g.alicdn.com/ilw/ding/0.8.9/scripts/dingtalk.js');
	//返回清除缓存
	var dingTalkNav = require('dd_config');
	mui.init({
		swipeBack: true //启用右滑关闭功能
	});
	$(function() {
		//钉钉右边按钮操作
		dingTalkNav.RightNavBar(false, "新增", "default");
		if(sessionStorage.libraryNameId && sessionStorage.libraryName) { //调出仓
			$("#wh_id").text(sessionStorage.libraryName);
			$("#wh_id").attr("data-id", sessionStorage.libraryNameId);

		} else {
			$("#wh_id").text("选择仓库");
			$("#wh_id").data("id", "");
		}

		if(sessionStorage.sortCatalogId && sessionStorage.sortName) { //产品分类
			$("#catalog_id").text(sessionStorage.sortName);
			$("#catalog_id").attr("data-id", sessionStorage.sortCatalogId);
		} else {
			$("#catalog_id").text("选择分类");
			$("#catalog_id").data("id", "");
		}
	});

	mui("body").on("tap", "#checkBegin", function() {
		var wh_id = $("#wh_id").attr("data-id").trim();
		var catalog_id = $("#catalog_id").attr("data-id").trim();
		var option = {};
		var dataModel = {
			"WhId": wh_id,
			"CatalogId": catalog_id,
			"StorageId": 0
		};
		abp.services.app.checkList.mobileCreate(dataModel, option)
			.done(function(data) {
				sessionStorage.setItem('check_id', data.id);
				clearSession();
				document.location.href = '../newCheckStock/checkInput.html';
			})
			.fail(function(data) {
				//	            	alert("无盘点数据！");
				var muiTips = require("muiTips");
				muiTips.alertTips(' ', data.message, 2, 3, "default");
			});
	});
	// 监听tap事件，解决 a标签 不能跳转页面问题jQuery
	mui('body').on('tap', 'a', function() {
		document.location.href = this.href + "?dd_nav_bgcolor=FFFF943E";
	});

	function clearSession() {
		sessionStorage.removeItem("sortCatalogId");
		sessionStorage.removeItem("sortName");
		sessionStorage.removeItem("libraryNameId");
		sessionStorage.removeItem("libraryName");
		sessionStorage.removeItem('createHome');
	}

	function clearSessionHome() {
		clearSession();
		document.location.href = "../../src/index.html?dd_nav_bgcolor=FFFF943E";
	}

	function clearSessionCreate() {
		clearSession();
		document.location.href = "../../src/inventoryRecord/index.html?dd_nav_bgcolor=FFFF943E";
	}
	if(sessionStorage.createHome) {
		//ios
		dingTalkNav.LeftNavBar(clearSessionHome);
		//ad
		dingTalkNav.leftAndroid(clearSessionHome);
	} else {
		//ios
		dingTalkNav.LeftNavBar(clearSessionCreate);
		//ad
		dingTalkNav.leftAndroid(clearSessionCreate);
	}

});